/**

 @Name：layuiAdmin 主页示例
 @Author：star1029
 @Site：http://www.layui.com/admin/
 @License：GPL-2
    
 */


layui.define(function(exports){
  var admin = layui.admin;
  
  //区块轮播切换
  layui.use(['admin', 'carousel'], function(){
    var $ = layui.$
    ,admin = layui.admin
    ,carousel = layui.carousel
    ,element = layui.element
    ,device = layui.device();

    //轮播切换
    $('.layadmin-carousel').each(function(){
      var othis = $(this);
      carousel.render({
        elem: this
        ,width: '100%'
        ,arrow: 'none'
        ,interval: othis.data('interval')
        ,autoplay: othis.data('autoplay') === true
        ,trigger: (device.ios || device.android) ? 'click' : 'hover'
        ,anim: othis.data('anim')
      });
    });
    
    element.render('progress');
    
  });

  //八卦新闻
  layui.use(['carousel', 'echarts'], function(){
    var $ = layui.$
    ,carousel = layui.carousel
    ,echarts = layui.echarts;
    
    var echartsApp = [], options = [
      {
        title : {
          subtext: '完全实况球员数据',
          textStyle: {
            fontSize: 14
          }
        },
        tooltip : {
          trigger: 'axis'
        },
        legend: {
          x : 'left',
          data:['罗纳尔多','舍普琴科']
        },
        polar : [
          {
            indicator : [
              {text : '进攻', max  : 100},
              {text : '防守', max  : 100},
              {text : '体能', max  : 100},
              {text : '速度', max  : 100},
              {text : '力量', max  : 100},
              {text : '技巧', max  : 100}
            ],
            radius : 130
          }
        ],
        series : [
          {
            type: 'radar',
            center : ['50%', '50%'], 
            itemStyle: {
              normal: {
                areaStyle: {
                  type: 'default'
                }
              }
            },
            data:[
              {value : [97, 42, 88, 94, 90, 86], name : '舍普琴科'},
              {value : [97, 32, 74, 95, 88, 92], name : '罗纳尔多'}
            ]
          }
        ]
      }
    ]
    ,elemDataView = $('#LAY-index-pageone').children('div')
    ,renderDataView = function(index){
      echartsApp[index] = echarts.init(elemDataView[index], layui.echartsTheme);
      echartsApp[index].setOption(options[index]);
      window.onresize = echartsApp[index].resize;
    };   
    //没找到DOM，终止执行
    if(!elemDataView[0]) return;
 
    renderDataView(0); 
  });

  //访问量
  layui.use(['carousel', 'echarts'], function(){
    var $ = layui.$
    ,carousel = layui.carousel
    ,echarts = layui.echarts;
    $.ajax({
      type: 'POST',
      url: '/admin/console/user_list',
      dataType: "json",
      headers: {token: '4b36adc7ff355357'},
      data: {},
      success: function (data) {
        var echartsApp = [], options = [
          {
            tooltip: {
              trigger: 'axis'
            },
            calculable: true,
            legend: {
              data: ['注册量', '活跃量']
            },

            xAxis: [
              {
                type: 'category',
                data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
              }
            ],
            yAxis: [
              {
                type: 'value',
                name: '注册量',
                axisLabel: {
                  formatter: '{value} '
                }
              },
              {
                type: 'value',
                name: '活跃量',
                axisLabel: {
                  formatter: '{value} '
                }
              }
            ],
            series: [
              {
                name: '注册量',
                type: 'line',
                data: data.register_list
              },
              {
                name: '活跃量',
                type: 'line',
                yAxisIndex: 1,
                data: data.active_list
              }
            ]
          }
        ]
            , elemDataView = $('#LAY-index-pagetwo').children('div')
            , renderDataView = function (index) {
          echartsApp[index] = echarts.init(elemDataView[index], layui.echartsTheme);
          echartsApp[index].setOption(options[index]);
          window.onresize = echartsApp[index].resize;
        };
        //没找到DOM，终止执行
        if (!elemDataView[0]) return;
        renderDataView(0);
      }
    })
  });

  //地图
  layui.use(['carousel', 'echarts'], function(){
    var $ = layui.$
    ,carousel = layui.carousel
    ,echarts = layui.echarts;
    $.ajax({
      type: 'POST',
      url: '/admin/console/user_nationwide',
      dataType: "json",
      headers: {token: '4b36adc7ff355357'},
      data: {},
      success: function (data) {
        var echartsApp = [], options = [
          {
            title: {
              text: '全国的 解说帝 用户分布',
              subtext: '仅供参考'
            },
            tooltip: {
              trigger: 'item'
            },
            dataRange: {
              orient: 'horizontal',
              min: 0,
              max: 10000,
              text: ['高', '低'],
              splitNumber: 0
            },
            series: [
              {
                name: '全国的 解说帝 用户分布',
                type: 'map',
                mapType: 'china',
                selectedMode: 'multiple',
                itemStyle: {
                  normal: {label: {show: true}},
                  emphasis: {label: {show: true}}
                },
                data: data.list
              }
            ]
          }
        ]
            , elemDataView = $('#LAY-index-pagethree').children('div')
            , renderDataView = function (index) {
          echartsApp[index] = echarts.init(elemDataView[index], layui.echartsTheme);
          echartsApp[index].setOption(options[index]);
          window.onresize = echartsApp[index].resize;
        };
        //没找到DOM，终止执行
        if (!elemDataView[0]) return;

        renderDataView(0);
      }
    })

  });

  //项目进展
  layui.use('table', function(){
    var $ = layui.$
    ,table = layui.table;
    
    table.render({
      elem: '#LAY-home-homepage2'
      ,url: '/admin/console/match_list' //模拟接口
      ,headers: {token: '4b36adc7ff355357'}
      ,cols: [[
        /*{type: 'checkbox', fixed: 'left'}*/
        {field: 'name', title: '名称'}
       // ,{field: 'time', title: '已过时间'}
        ,{field: 'type', title: '赛程情况'
          ,templet: function(d){
            if(d.type == 3){
              return '<del style="color: #5FB878;">'+ d.type_name +'</del>'
            }else if(d.type == 2){
              return '<span style="color: #FFB800;">'+ d.type_name +'</span>'
            }else if(d.type == 1){
              return '<span style="color: #FF5722;">'+ d.type_name +'</span>'
            }
          }
        }
      ]]
      ,skin: 'line'
    });
  });
  
  //回复留言
  admin.events.replyNote = function(othis){
    var nid = othis.data('id');
    layer.prompt({
      title: '回复留言 ID:'+ nid
      ,formType: 2
    }, function(value, index){
      //这里可以请求 Ajax
      //…
      layer.msg('得到：'+ value);
      layer.close(index);
    });
  };

  exports('sample', {})
});